<template>
  <div class="page">
    <el-form :model="searchForm" label-position="left" inline label-suffix="：" size="small">
      <div class="flex wap flex-start">
        <el-form-item label="学生">
          <check-stu :itemId="searchForm.stuid" @checkedItem="checkedStu"/>
        </el-form-item>
        <el-form-item label="老师">
          <check-emp :itemId="searchForm.empid" @checkedItem="checkedEmp"/>
        </el-form-item>
        <el-form-item label="上课类型">
          <el-select v-model="searchForm.status" placeholder="请选择上课类型">
            <el-option label="正常" :value="1"></el-option>
            <el-option label="请假" :value="2"></el-option>
            <el-option label="补课" :value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间范围">
          <el-date-picker v-model="dateTime" type="daterange" range-separator="~" start-placeholder="开始日期"
            end-placeholder="结束日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="">
          <el-button type="primary" @click="getData">查询</el-button>
        </el-form-item>
      </div>
    </el-form>
    <div class="flex wap flex-start" style="padding: 0px 0 10px 0">
      <!-- <el-button type="danger" @click="del">删除</el-button> -->
    </div>
    <el-table :data="tableData" border style="width: 100%"  height="600"  :header-cell-style="{
        background: '#eef1f6',
        color: '#606266',
        'text-align': 'center'
      }"
      :cell-style="{ 'text-align': 'center' }">
      <!-- <el-table-column type="selection"></el-table-column> -->

      <!-- <el-table-column prop="signlogid" label="签到记录id" width="100"></el-table-column> -->
      <el-table-column prop="stuname" label="学生名字"></el-table-column>
      <el-table-column prop="stuphone" label="手机号"></el-table-column>
      <el-table-column prop="lessioninfo" label="课程信息" show-overflow-tooltip></el-table-column>
      <el-table-column prop="empname" label="任课老师"></el-table-column>
      <el-table-column prop="status" label="上课类型">
        <template slot-scope="scop">
          <el-tag type="success" v-if="scop.row.status == 1">正常</el-tag>
          <el-tag type="warning" v-if="scop.row.status == 2">请假</el-tag>
          <el-tag type="danger" v-if="scop.row.status == 3">补课</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="content" label="签到备注" show-overflow-tooltip></el-table-column>
      <el-table-column prop="createtime" label="创建时间"></el-table-column>
      <el-table-column prop="creator" label="签到人" width="100"></el-table-column>
      <el-table-column prop="" label="操作" width="80">
        <template slot-scope="scop">
          <!-- <el-button type="primary" icon="el-icon-edit" circle></el-button> -->
          <el-button type="danger" icon="el-icon-delete" circle @click="del(scop.row.signlogid)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="float:right;padding:10px">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-sizes="[10, 20, 50, 100, 200]"
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { findSignLog, delSignLog } from "@/api/user";
import checkStu from "@/views/components/checkStu";
import checkEmp from "@/views/components/checkEmp";
export default {
  components: {
    checkStu,
    checkEmp
  },
  data() {
    return {
      total: 0,
      pageNum: 1,
      pageSize: 10,
      dateTime: [],
      tableData: [],
      searchForm: {
        status:'',
        empid: "",
        stuid: "",
        begintime: '',
        endtime: ''
      }
    };
  },
  computed: {
    queryData() {
      return {
        status: this.searchForm.status,
        empid: this.searchForm.empid,
        stuid: this.searchForm.stuid,
        begintime: this.searchForm.begintime,
        endtime: this.searchForm.endtime,
        pageNum: this.pageNum,
        pageSize: this.pageSize
      };
    }
  },
  watch: {
    dateTime(n) {
      if (n) {
        this.searchForm.begintime = n[0]
        this.searchForm.endtime = n[1]
      } else {
        this.searchForm.begintime = ''
        this.searchForm.endtime = ''
      }
    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    checkedStu(val) {
      this.searchForm.stuid = val
    },
    checkedEmp(val) {
      this.searchForm.empid = val
    },
    async getData() {
      const res = await findSignLog.post(this.queryData);
      if (res.resultCode === "000000") {
        this.tableData = res.data.signloglist;
        this.total = res.data.count;
      } else {
        this.$message.error(res.resultInfo);
      }
    },
    del(ids) {
      if (ids) {
        this.$confirm("此操作将删除该项目, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            this.delItem(ids)
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除"
            });
          });
      }
    },
    async delItem(ids) {
      const res = await delSignLog.post({ signlogid: ids });
      if (res.resultCode === "000000") {
        this.$message.success(res.resultInfo);
        this.getData()
      } else {
        this.$message.error(res.resultInfo);
      }
    },
    handleSizeChange(val) {
      this.pageNum = 1;
      this.pageSize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this.getData();
    }
  }
};
</script>
<style lang="less" scoped></style>
